package com.wyf.video

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.view.WindowManager
import com.wyf.video.adapter.MyPagerAdapter
import kotlinx.android.synthetic.main.activity_main.*
import org.jetbrains.anko.sdk25.coroutines.onClick

class MainActivity : AppCompatActivity() {

    var fragList= ArrayList<Fragment>()
    var titleList = ArrayList<String>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)

        initTabLayout()
        initEvent()

    }

     fun initEvent(){
         main_searchview.onClick {
             val intent = Intent()
             //获取intent对象
             intent.setClass(this@MainActivity,SearchActivity::class.java)
             // 获取class是使用::反射
             startActivity(intent)
         }


     }

    private fun initTabLayout(){

        var hotFragment = HotFragment()
        var newFragment = NewFragment()

        fragList.add(newFragment)
        fragList.add(hotFragment)
        titleList.add("最新")
        titleList.add("热门")


        var adapter = MyPagerAdapter(fragList, titleList, supportFragmentManager)
        main_viewpage.adapter = adapter
        main_tablayout.setupWithViewPager(main_viewpage)

    }
}
